package com.abbas.CayTcore.base

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding

abstract class BaseActivity<V: BaseView,P: BasePresenter<V, *>,VB: ViewBinding> : AppCompatActivity(), BaseView {

    protected lateinit var presenter: P
    private lateinit var _binding:VB
    protected val binding get() = _binding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        _binding = getViewBinding()
        setContentView(binding.root)

        presenter = initPresenter()
        presenter.let {
            it.attach(this as V)
            lifecycle.addObserver(it)
        }

        initData()
        initEvent()
    }



    abstract fun getViewBinding(): VB

    abstract fun initPresenter() : P

    abstract fun initData()

    abstract fun initEvent()

    override fun onDestroy() {
        super.onDestroy()
    }

}